package com.fanhao.dllo.justforyou.application;

import android.app.Application;
import android.content.Context;

import com.fanhao.dllo.justforyou.entity.greendao.DaoMaster;
import com.fanhao.dllo.justforyou.entity.greendao.DaoSession;

/**
 * Created by Risky on 15/10/21.
 */
public class BaseApplication extends Application {

    private static Context context;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
//        context = getApplicationContext();
    }

    public static Context getContext() {
        return context;
    }
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;

    public static DaoMaster getDaoMaster() {

        if (daoMaster == null) {
            DaoMaster.OpenHelper helper = new DaoMaster
                    .DevOpenHelper(context, "fanhao", null);

            daoMaster = new DaoMaster(
                    helper.getWritableDatabase());
        }
        return daoMaster;

    }

    public static DaoSession getDaoSession() {

        if (daoSession == null) {
            if(daoMaster == null)
                getDaoMaster();
            daoSession = daoMaster.newSession();
        }
        return daoSession;

    }



}
